package com.zs.zcerp.approval.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zs.zcerp.approval.entity.QhChkmgrmEntity;
import com.zs.zcerp.approval.mapper.QhChkmgrmMapper;
import com.zs.zcerp.approval.service.IQhChkmgrmService;
import com.zs.zcerp.common.entity.FebsConstant;
import com.zs.zcerp.common.entity.QueryRequest;
import com.zs.zcerp.common.utils.DateUtil;
import com.zs.zcerp.common.utils.SortUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Henry
 *
 * @author admin
 */

@Service
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class QhChkmgrmServiceImpl extends ServiceImpl<QhChkmgrmMapper, QhChkmgrmEntity> implements IQhChkmgrmService {

    @Autowired
    private QhChkmgrmMapper qhChkmgrmMapper;

    @Override
    @DS("ypdb")
    public void yqSignStatus(String orderNo) {
        qhChkmgrmMapper.yqSignStatus(orderNo);
    }

    @Override
    @DS("ypdb")
    public void rejectYqStatus(String orderNo) {
        qhChkmgrmMapper.rejectYqStatus(orderNo);
    }


    @Override
    @DS("oracle2")
    public void orderSignStatus(String orderNo,String status) {
        qhChkmgrmMapper.orderSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void GAPOSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.GAPOSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void MDPOSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.MDPOSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void PO6SignStatus(String orderNo, String status) {
        qhChkmgrmMapper.PO6SignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void PGSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.PGSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void KFPSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.KFPSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void WOSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.WOSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void FATRSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.FATRSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void XPOSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.XPOSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void FAINSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.FAINSignStatus(orderNo,status);
    }

    @Override
    @DS("oracle2")
    public void XPCSignStatus(String orderNo, String status) {
        qhChkmgrmMapper.XPCSignStatus(orderNo,status);

    }

    @Override
    @DS("oracle2")
    public void WPGignStatus(String orderNo, String status) {
        qhChkmgrmMapper.WPGignStatus(orderNo,status);
    }


    @Override
    @DS("oracle") //从oracle库数据查询
    public void deleteByOrderyNo(String orderyNo) {
        baseMapper.delete(new QueryWrapper<QhChkmgrmEntity>().eq("ORDER_NO",orderyNo));

    }

    @Override
    @DS("oracle") //从oracle库数据查询
    public IPage<QhChkmgrmEntity> signList(QhChkmgrmEntity qhChkmgrmEntity, QueryRequest request) {
        if (StringUtils.isNotBlank(qhChkmgrmEntity.getCreateTimeFrom()) &&
                StringUtils.equals(qhChkmgrmEntity.getCreateTimeFrom(), qhChkmgrmEntity.getCreateTimeTo())) {
            qhChkmgrmEntity.setCreateTimeFrom(DateUtil.formatDateTime(qhChkmgrmEntity.getCreateTimeFrom()));
            qhChkmgrmEntity.setCreateTimeTo(DateUtil.formatDateTime(qhChkmgrmEntity.getCreateTimeTo()));
        }
        Page<QhChkmgrmEntity> page = new Page<>(request.getPageNum(), request.getPageSize());
        page.setSearchCount(false);
        page.setTotal(baseMapper.countSignDetail(qhChkmgrmEntity));
        SortUtil.handlePageSort(request, page, "sendTime", FebsConstant.ORDER_DESC, false);
        return baseMapper.findSignDetailPage(page, qhChkmgrmEntity);
    }


}
